package com.cloud.pole.common.util;

import java.util.ArrayList;
import java.util.List;

/*
*2019年3月26日
*cloud-common
*author:frank-chen
*/
public class ListUtils {

	  /**
     * 转换list
     * @param fromList
     * @param tClass
     * @param <F>
     * @param <T>
     * @return
     */
    public static<F,T> List<T> copyListProperties(List<F> fromList, Class<T> toClass){
        if(fromList == null){
            return null;
        }
        List<T> tList = new ArrayList<>();
        for(F f : fromList){
            T t = entityToModel(f, toClass);
            tList.add(t);
        }
        return tList;
    }
    
    /**
     * 转换类
     * @param entity
     * @param modelClass
     * @return
     */
    public static<F,T> T entityToModel(F entity, Class<T> modelClass) {
        Object model = null;
        if (entity == null || modelClass ==null) {
            return null;
        }
        try {
            model = modelClass.newInstance();
        } catch (InstantiationException e) {
        	e.printStackTrace();
        } catch (IllegalAccessException e) {
        	e.printStackTrace();
        }
        org.springframework.beans.BeanUtils.copyProperties(entity, model);
        return (T)model;
    }
}
